<?php
    $owner = isset($_GET['owner'])?$_GET['owner']:'';
 if(!isset($sp))	
  	$sp=explode("/",$_SERVER['PHP_SELF']);

  if($_SERVER['HTTP_HOST'] == "localhost" || $_SERVER['HTTP_HOST'] == "192.168.1.34")
   {
	  $sp[1] = '/' . $sp[1];
   }
  else
	  $sp[1] = '';
  
  $w_root = $_SERVER['SERVER_NAME'] . $sp[1];
  $w_root = str_replace('//','/',$w_root);
  $w_root = str_replace('\\\\','\\',$w_root);
  
  $s_root = $_SERVER['DOCUMENT_ROOT'] . $sp[1];
  $s_root = str_replace('//','/',$s_root);
  $s_root = str_replace('\\\\','\\',$s_root); 
/*========End Setting up web root and server root =============*/

    if(empty($owner))
    {
        header("Location: '.$w_root.'");
    } 
    
    
 	require_once $s_root. '/libraryfiles/config.php'; // 
    $seller = $owner;
    $seller_id = $owner;
     // personal page seller
            $strin          ="";
            $st             = $owner;    
            $company        = new company();
            $company        ->getcompany($strin,$st);  
            $last_word = $company->shorturl;
            $de[0] = $last_word; 
     // end personal  

    ?>
<?php
 include(S_ROOT.'/company/header_top.php');?>
<body> 
<?php include(S_ROOT.'/includefiles/header.php');?>
<?php include(S_ROOT.'/company/headerseller.php');


if(!empty($_GET['cat_p']))
{
    $cat_s = $_GET['cat_p'];
}
else
{
    $cat_s = $seller_cat;
}
$category_S =   $cat_s;
$category = isset($_GET['cat_id'])?$_GET['cat_id']:$cat_s;
$category_id = isset($_GET['cat_id'])?$_GET['cat_id']:$category_S;
$subcat = isset($_GET['cat_id'])?$_GET['cat_id']:'';
$qstring = 'owner='.$owner;

if(isset($cat_s))
    {
    	$parent        = $cat_s;
    	$sql_1         = "SELECT id, parent_id FROM tblcategory WHERE parent_id = $parent";
    	$result_1      = mysql_query($sql_1);
    	$id            = array();
    	if(dbNumRows($result_1))
        {
    	while($row_1   = mysql_fetch_assoc($result_1))
            {
        		$id[]      = $row_1['id'];
        	}
    	$category      = implode(',',$id);        
    	}
    }


    //for cate
    $cateid = 8;
    $show = 1;
    $char = 20;
    $obj=new by_category();                    
    $more_value = 20;   

?>

<div style="height:20px; clear:both"></div>

<!-- content -->  

  <!-- First Band (Image) -->
    
  <div class="row">
        <div class="three columns">
         <?php
        	 include(S_ROOT.'/company/browser.php');
         ?> 
        </div>
        
        <div class="nine columns">
            <div style="margin-left: 15px">
                    <!-- content -->
                            <?php 	
                               if(!empty($_GET['color']))
                               {
                                  $mix = "AND mix.color_id='".$_GET['color']."'";
                               }
                               else if(!empty($_GET['size']))
                               {
                                  $mix = "AND mix.size_id='".$_GET['size']."'";
                               }
                               else if(!empty($_GET['brand']))
                               {
                                  $mix = "AND mix.brand_name='".$_GET['brand']."'";
                               }
                               else
                               {
                                  $mix ='';
                               }
                               
                               
                                		$rowsPerPage = isset($_GET['num'])?$_GET['num']:'12';
                                		$select = ("SELECT p.product_type, p.product_name, pic.product_id, pic.category_id, img.thumbnail,img.images, pip.price, pip.country_id,p.id,pip.pid
                                				FROM `tblproduct` AS p LEFT JOIN `tblimage` AS img ON p.id = img.product_id
                                				LEFT JOIN `tblproduct_in_pharmacy` AS pip ON p.id = pip.product_id 
                                				LEFT JOIN tblproduct_in_category AS pic ON p.id = pic.product_id
                                				INNER JOIN tbl_color_size AS mix ON mix.pid=p.id
                                				WHERE pic.category_id IN ($category) AND pip.status = 1 $mix GROUP BY p.id");
                                		$result     = mysql_query(getPagingQuery($select, $rowsPerPage));
                                		$pagingLink = getPagingLink($select, $rowsPerPage, $qstring);
                                       // echo $select;die();
                            ?>
                        
                        
                        <div class="twelve columns">
                            <div class="bo_eee radius1 ba_fff pad_10" style="margin-right: 15px; margin-bottom:15px;">
                                <?php echo getCategoryName($category_id);?>
                            </div>        
                        </div> 
                        <?php
                            if(!empty($_GET['cat_id']))
                                {
                                    $catid  = '&cat_id='.$_GET['cat_id'];
                                }
                                if(!empty($_GET['cat_p']))
                                {
                                    $cat_idp  = '&cat_p='.$_GET['cat_p'];
                                }
                        	$i = 0;
                        		if(dbNumRows($result)>0){
                        		while($data=mysql_fetch_assoc($result)){
                        		$pharmacy=mysql_query("SELECT COUNT(DISTINCT pharmacy_id) AS pid
                        		FROM tblproduct_in_pharmacy WHERE product_id=".$data['id']." AND country_id=".$data['country_id']);
                        		
                        		$price=mysql_query("SELECT price,regular_price FROM tblproduct_in_pharmacy WHERE product_id=".$data['id']." ORDER BY price ASC LIMIT 0,1");
                        		$myprice=mysql_fetch_assoc($price);
                        		$price1=mysql_query("SELECT price,regular_price FROM tblproduct_in_pharmacy WHERE product_id=".$data['id']." ORDER BY price DESC LIMIT 0,1");
                        		$myprice1=mysql_fetch_assoc($price1);
                        		if($i==0)
                        		{
                        		echo '';			
                        		}else{
                        		echo '';	
                        		}
                        		$i++;
                        	?> 
                        <div class="three columns">
                            <div class="product-cat">
                            <div class="image_por">
                                <a href="product_detail.php?product_id=<?php echo $data['id']?><?php if(!empty($cat_idp)) {echo $cat_idp;}?><?php if(!empty($catid)) {echo $catid;}?>" title="<?php echo $data['product_name'] ?>"><img src="<?php echo W_S_IMAGES_DIR.$data['thumbnail'] ?>"></a>
                            </div>         
                            <div class="pro-title">
                                <a href="product_detail.php?product_id=<?php echo $data['id']?><?php if(!empty($cat_idp)) {echo $cat_idp;}?><?php if(!empty($catid)) {echo $catid;}?>" title="<?php echo $data['product_name'] ?>"><?php echo $data['product_name'] ?></a>
                            </div>
                            <div class="add-tocart">
                                <a class="btn btn-mini btn-success" href="../libraryfiles/cart-functions.php?action=add&amp;pid=<?php echo $data['pid'] ?>"><i class="icon-shopping-cart icon-white"></i> add to cart</a>
                            </div>
                            <span class="price">
                              <?php 
                                  if($myprice['price']==$myprice1['price'])
                                        {
                                            echo $myprice['price']."$";
                                        }
                                        else
                                        {
                                            echo $myprice['price'] .' - '. $myprice1['price']."$" ; 
                                        }
                              ?>
                            </span>        
                            </div>
                        </div>
                        <?php  } 
                    		}else{
                    	?>
                    
                        <div style="margin-left:15px;">
                    		<div class="twelve columns">
                                <div class="bo_eee radius1 ba_fff pad_10" style="margin-right: 15px; margin-bottom:15px;">
                                    <h3 align="center" style="text-align:center;">No Product in <?php echo getCategoryName($category_id);?> </h3>
                                </div>
                            </div>
                      </div>
                    
                        <?php		
                    		}
                    	 ?>
                    <!-- end content -->	
        
        
                    <!-- nav page -->
        		<div class="twelve columns">
                    <div class="bo_eee radius1 ba_fff pad_10" style="margin-right: 15px; margin-bottom:15px;">
        			<div class="wp-pagenavi">
        				<?php echo $pagingLink;?>
                        <div class="clear"></div>
        			</div>
                    </div>
                </div>
                <!-- end nav page -->
                
            </div>
        </div>
  </div>
  
  <div class="clear"></div>
<?php include(S_ROOT.'/includefiles/bottom_company.php');?>
  <!-- Included JS Files (Compressed) -->
  
  <!-- Initialize JS Plugins -->
    <script src="<?php echo W_ROOT;?>/templates/javascripts/bootstrap-dropdown.js"></script>
    <script src="<?php echo W_ROOT;?>/templates/javascripts/app.js"></script>        
</body>
</html>